﻿using AutoTest.Business.Dto.UserInfo;
using AutoTest.Business.IServices;
using AutoTest.Business.Vo.UserInfo;
using AutoTest.Domain.Enums;
using AutoTest.Framework.Api;
using AutoTest.Framework.Pager;
using Microsoft.AspNetCore.Mvc;

namespace AutoTest.WebApi.Controllers.Admin
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("admin/user/manage")]
    public class UserManageController(IUserService userService) : Controller
    {
        private readonly IUserService _userService = userService;


        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="searchDto"></param>
        /// <returns></returns>
        [HttpGet("page")]
        public async Task<ApiResult<PagedList<UserInfoListVo>>> PageSearchUserInfoListAsync([FromQuery] UserInfoPageSearchDto searchDto)
        {
            return await ApiResult<PagedList<UserInfoListVo>>.Successed(() => _userService.PageSearchUserInfoListAsync(searchDto));
        }


        /// <summary>
        /// 同步结果
        /// </summary>
        /// <returns></returns>
        [HttpGet("detail/{userid}")]
        public async Task<ApiResult<UserInfoDetailVo>> GetUserInfoDetailAsync([FromRoute] long userid)
        {
            return await ApiResult<UserInfoDetailVo>.Successed(() => _userService.GetUserInfoDetailAsync(userid));
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task<ApiResult<UserInfoDetailVo>> AddUserInfoAsync([FromBody] UserInfoAddDto addDto)
        {
            return await ApiResult<UserInfoDetailVo>.Successed(() => _userService.AddUserInfoAsync(addDto));
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        [HttpPut("update/{userid}")]
        public async Task<ApiResult<UserInfoDetailVo>> EditUserInfoAsync([FromRoute] long userid,[FromBody] UserInfoAddDto addDto)
        {
            return await ApiResult<UserInfoDetailVo>.Successed(() => _userService.EditUserInfoAsync(userid,addDto));
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        [HttpPut("enable/{userid}")]
        public async Task<ApiResult<UserInfoDetailVo>> EnableUserInfoAsync([FromRoute] long userid)
        {
            return await ApiResult<UserInfoDetailVo>.Successed(() => _userService.ChangeUserStatusAsync(userid,EnumStatus.Enable));
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        [HttpPut("disable/{userid}")]
        public async Task<ApiResult<UserInfoDetailVo>> DisableUserInfoAsync([FromRoute] long userid)
        {
            return await ApiResult<UserInfoDetailVo>.Successed(() => _userService.ChangeUserStatusAsync(userid, EnumStatus.Disable));
        }
    }
}
